package order;

import common.db.*;
import common.main.*;

import java.util.*;

public class BasketAddBean extends MainBean
{
	public void funcExecute() throws Exception
	{
		String gcode = (String)inputTable.get("gcode");
		String id = (String)inputTable.get("id");
		String amount = (String)inputTable.get("amount");
		String dtype = (String)inputTable.get("dtype");
		String client = (String)inputTable.get("client");
		String wbfrom = (String)inputTable.get("wbfrom");
		String pway = (String)inputTable.get("pway");
		
		int purcharse_v = Integer.parseInt(amount);
		
		System.out.println("gcode" + gcode);
		System.out.println("user_id" + id);
		System.out.println("amount" + purcharse_v);
		System.out.println("client" + client);

		System.out.println("222");
		String os = "";
		if(wbfrom.equals("B"))
		{
			os="1";
		}
		else if(wbfrom.equals("W"))
		{
			os="7";
		}
		else if(wbfrom.equals("O"))
		{
			os="2";
		}
		
		queryBuffer = new StringBuffer("");
		queryBuffer.append("SELECT CODE, GOODS_CODE FROM ORDERLIST WHERE GOODS_CODE='"+gcode+"' AND ORDER_STATE='"+os+"' AND USE_YN='Y'");	
		DBExecute dbe = new DBExecute(queryBuffer.toString());
		ArrayList resultList = dbe.getDataList();
		
		int resultCount = resultList.size();
		if(resultCount==0)
		{
			System.out.println("11111111111111111");
			queryBuffer = new StringBuffer("");
			queryBuffer.append("INSERT INTO ORDERLIST (CODE,GOODS_CODE, SHOPPER_ID, PURCHARSE_VALUE, PURCHARSE_WAY, ORDER_STATE, PAYMENT_WAY, DELIVERY_METHOD, OR_DATE, SAVING_POINT,USE_YN, REG_ID, REG_DATE, REG_IP, UPD_ID, UPD_DATE, UPD_IP) ");
			queryBuffer.append("VALUES ");
			queryBuffer.append("(ORDERLIST_SEQ.NEXTVAL, '"+gcode+"', '"+id+"', '"+purcharse_v+"', '"+pway+"', '"+os+"',1, '"+dtype+"', SYSDATE, 199,'Y', '"+id+"',SYSDATE, '"+client+"', '"+id+"', SYSDATE, '"+client+"')");

			dbe = new DBExecute(queryBuffer.toString());
			outputList = dbe.getDataList();			
		}
		else
		{
			System.out.println("222222222222222222");
			queryBuffer = new StringBuffer("");
			queryBuffer.append("UPDATE ORDERLIST SET ");
			queryBuffer.append("PURCHARSE_VALUE=PURCHARSE_VALUE+"+purcharse_v+", ");
			queryBuffer.append("UPD_ID='"+id+"',UPD_DATE=SYSDATE, UPD_IP='"+client+"' WHERE GOODS_CODE='"+gcode+"'");

			dbe = new DBExecute(queryBuffer.toString());
			outputList = dbe.getDataList();				
		}
	}
}
